﻿using Gobang.ToolClass;
using Gobang.ToolClass.Area;

namespace Gobang.Server.Area
{
    internal class AreaCenter
    {
        private readonly List<AreaNode> _areaNodes;
        public List<AreaNode> AreaNodes { get { return _areaNodes; } }
        public AreaCenter()
        {
            _areaNodes = new List<AreaNode>();
            AddArea();
            CreateRoom();
            CreateDesk();
        }
        private void AddArea()
        {
            var an0 = new AreaNode
            {
                AreaId = "899dba69-c121-e60e-d667-c4d6b6096a33",
                AreaName = "人机对决"
            };
            _areaNodes.Add(an0);

            var an1 = new AreaNode
            {
                AreaId = "6afb1aa5-e6fc-c47f-8a35-72090ce3913d",
                AreaName = "普通区一"
            };
            _areaNodes.Add(an1);

            var an2 = new AreaNode
            {
                AreaId = "4f02aa2e-1172-34b6-3afb-a636d4720b44",
                AreaName = "普通区二"
            };
            _areaNodes.Add(an2);

            var an3 = new AreaNode
            {
                AreaId = "7792318d-405c-012f-0029-41e5a5055e8e",
                AreaName = "普通区三"
            };
            _areaNodes.Add(an3);

            var an4 = new AreaNode
            {
                AreaId = "6fdc5ad8-daac-ac31-c536-56e50bc4f252",
                AreaName = "高手区一"
            };
            _areaNodes.Add(an4);

            var an5 = new AreaNode
            {
                AreaId = "9bae04fb-7fa2-5141-9052-443f9a6a8a86",
                AreaName = "高手区二"
            };
            _areaNodes.Add(an5);

            var an6 = new AreaNode
            {
                AreaId = "6f044f53-fb07-2e00-7f32-40006f883e3c",
                AreaName = "高手区三"
            };
            _areaNodes.Add(an6);
        }
        private void CreateRoom()
        {
            int roomNum = 10;
            foreach (var item in _areaNodes)
            {
                if (item.AreaName.Contains("人机"))
                {
                    item.AreaNodes.Add(new AreaNode
                    {
                        AreaId = Guid.NewGuid().ToString(),
                        AreaName = "房间1"
                    });
                    continue;
                }

                for (int i = 1; i < roomNum; i++)
                {
                    item.AreaNodes.Add(new AreaNode
                    {
                        AreaId = Guid.NewGuid().ToString(),
                        AreaName = "房间" + i
                    });
                }
            }
        }
        private void CreateDesk()
        {
            foreach (var item in _areaNodes)
            {
                if (item.AreaName.Contains("人机"))
                {
                    var room = item.AreaNodes.FirstOrDefault().Rooms = new List<Room>();
                    room.Add(new Room
                    {
                        RoomId = Guid.NewGuid().ToString(),
                        RoomName = "桌号1"
                    });
                    room.Add(new Room
                    {
                        RoomId = Guid.NewGuid().ToString(),
                        RoomName = "桌号2"
                    });
                    continue;
                }

                foreach (var item2 in item.AreaNodes)
                {
                    item2.Rooms = new List<Room>();
                    for (int i = 1; i < 11; i++)
                    {
                        item2.Rooms.Add(new Room
                        {
                            RoomId = Guid.NewGuid().ToString(),
                            RoomName = "桌号" + i
                        });
                    }
                }
            }
        }
        public override string ToString()
        {
            return this.AreaNodes.SerializeObject();
        }
    }
}
